package ar.edu.unrn.lia.service.impl;

import java.util.List;
import java.util.Map;

import javax.inject.Inject;
import javax.inject.Named;

import org.springframework.transaction.annotation.Transactional;

import ar.edu.unrn.lia.dao.PropietarioDAO;
import ar.edu.unrn.lia.model.Inquilino;
import ar.edu.unrn.lia.model.Propietario;
import ar.edu.unrn.lia.service.CuentaService;
import ar.edu.unrn.lia.service.PropietarioService;

@Named("propietarioService")
public class PropietarioServiceImpl implements PropietarioService {

	@Inject
	PropietarioDAO entityDAO;
	@Inject
	CuentaService cuentaService;

	public PropietarioDAO getEntityDAO() {
		return entityDAO;
	}

	@Transactional(readOnly = true)
	public Long getCount(Map<String, String> filters) {
		return getEntityDAO().count(
				getEntityDAO().getSearchPredicates(getEntityDAO().rootCount(),
						filters));
	}

	@Transactional(readOnly = true)
	public List<Propietario> getList(Integer page, Integer pagesize,
			Map<String, String> filters, String sortField, Boolean asc) {
		return getEntityDAO().listwithPag(
				getEntityDAO().getSearchPredicates(getEntityDAO().rootCount(),
						filters), page, pagesize, sortField, asc);
	}
	
	@Transactional(readOnly = true)
	public List<Propietario> getList(Integer page, Integer pagesize,
			Map<String, String> filters, Map<String, Boolean> sorts) {
		return getEntityDAO().listwithPag(
				getEntityDAO().getSearchPredicates(getEntityDAO().rootCount(),
						filters), page, pagesize, sorts);
	}

	@Transactional
	public void save(Propietario entity) {
		cuentaService.crearCuenta(entity);
		getEntityDAO().create(entity);
	}

	@Transactional
	public void delete(Propietario entity) {
		getEntityDAO().delete(entity);
	}

	@Transactional
	public void update(Propietario entity) {
		getEntityDAO().update(entity);
	}

	public Propietario getEntityById(Long id) {
		return getEntityDAO().read(id);
	}

	public List<Propietario> getAll() {
		return getEntityDAO().findAll();
	}

	public List<Propietario> findByQuery(String query, String propertyFilter,
			String orderDirection) {
		return getEntityDAO()
				.findByQuery(query, propertyFilter, orderDirection);
	}

}